{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7152ef60-c862-4dee-b05f-26e1a2ab430b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "4de17b7a-b96d-4f21-8bbf-98de7757011e",
   "metadata": {},
   "source": [
    "## 继承"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a2c73a82-d0f3-45af-a953-92b99dfdf391",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student:\n",
    "    def __init__(self, name, age):\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "    \n",
    "    def introduce(self):\n",
    "        print(f\"您好, 我是{self.name}，{self.age:0.0f}岁\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cbfec3ba-46cf-4753-b62f-922df00fe9f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "type(Student.introduce)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54e25eee-187d-49e9-8feb-57e14f30161c",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "## 生成器表达式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c81799f0-e349-4847-ab81-c2fdaad5db61",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<generator object <genexpr> at 0x000002088CB6CD40>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x**2 for x in range(1,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1922221f-8648-438f-ab67-7c1e74747809",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in (x**2 for x in range(1,4)):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2f8f6d41-93a1-4577-8712-bcaefe430659",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(x**2 for x in range(1,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "68795142-6640-4430-be7e-fa4f794f477e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 4, 9)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tuple(x**2 for x in range(1,4))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74877e07-f000-4465-9926-d912ea8a38cf",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "注意，请注意下面的生成器括号前的星号`*`和其末尾的逗号`,`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "820458bd-06d7-4633-88c7-9d41e9ec787e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 4, 9)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "*(x**2 for x in range(1,4)),"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a93ca41a-4ab7-4450-8a93-efd60181a03a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f103be4-6f3f-4fd6-97e8-6617570b224c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
